package com.boot.apollo.modules.guava;

import com.google.common.util.concurrent.RateLimiter;

import java.text.SimpleDateFormat;
import java.util.Date;

public class RateLimiterTest {

    public static void main(String[] args) {
        RateLimiter limiter = RateLimiter.create(1.0); // 这里的1表示每秒允许处理的量为1个
        for (int i = 1; i <= 10; i++) {
            String start = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
            limiter.acquire();// 请求RateLimiter, 超过permits会被阻塞
            String end = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
            System.out.println("call execute.." + i);
            System.out.println("start time:" + start);
            System.out.println("end time:" + end);
        }
    }





}
